package com.example.newdemo.http.client;

public class HttpTest {


//    /**
//     * @param args
//     * @throws IOException
//     * @throws ClientProtocolException
//     */
//
//    public static class WebClientDevWrapper {
//
//
//        public static HttpClient wrapClient(HttpClient base) {
//            try {
//                SSLContext ctx = SSLContext.getInstance("TLS");
//                X509TrustManager tm = new X509TrustManager() {
//                    public java.security.cert.X509Certificate[] getAcceptedIssuers() {
//                        return null;
//                    }
//                    public void checkClientTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {}
//                    public void checkServerTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {}
//                    public void checkClientTrusted(
//                            java.security.cert.X509Certificate[] chain,
//                            String authType)
//                            throws java.security.cert.CertificateException {
//
//                    }
//                    public void checkServerTrusted(
//                            java.security.cert.X509Certificate[] chain,
//                            String authType)
//                            throws java.security.cert.CertificateException {
//
//                    }
//                };
//                ctx.init(null, new TrustManager[] { tm }, null);
//                SSLSocketFactory ssf = new SSLSocketFactory(ctx);
//                ssf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
//
//                SchemeRegistry registry = new SchemeRegistry();
//                registry.register(new Scheme("https", ssf, 443));
//                ThreadSafeClientConnManager mgr = new ThreadSafeClientConnManager(base.getParams(), registry);
//
//                return new DefaultHttpClient(mgr, base.getParams());
//            } catch (Exception ex) {
//                ex.printStackTrace();
//                return null;
//            }
//        }
//    }
//
//
//
//
//    public static void start() throws ClientProtocolException, IOException{
//
//
//        DefaultHttpClient httpclient = new DefaultHttpClient();// 得到httpclient实例
//        httpclient = (DefaultHttpClient) WebClientDevWrapper.wrapClient(httpclient);
//
//        HttpResponse response = null;
//        HttpEntity entity = null;
//        StringBuffer sb=null;
//        String user="";
//        String pwd="";
//        // 登陆请求
//        HttpPost httpost = new HttpPost("https://www.peuland.com/captcha/captchaimg.php");
//        List<NameValuePair> nvps = new ArrayList<NameValuePair>();
//        nvps.add(new BasicNameValuePair("user", "wwaly@qq.com"));
//        nvps.add(new BasicNameValuePair("pwd", "111111"));
//        nvps.add(new BasicNameValuePair("type", "100000"));
//        //nvps.add(new BasicNameValuePair("button", "提交"));
//        httpost.setEntity(new UrlEncodedFormEntity(nvps, "utf8"));
//        File file = new File("d:/2.jpg");
//        FileEntity reqEntity = new FileEntity(file, "binary/octet-stream");
//        httpost.setEntity(reqEntity);
//        httpost.setHeader("Accept", "image/jpeg, application/x-ms-application, image/gif, application/xaml+xml, image/pjpeg, application/x-ms-xbap, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*");
//        httpost.setHeader("Referer", "https://www.peuland.com/captcha/captcha_demo.htm");
//        httpost.setHeader("Accept-Language", "zh-CN");
//        httpost.setHeader("User-Agent", "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; QQDownload 760; SLCC2; .NET CLR 2.0.50727; .NET4.0C; .NET4.0E; InfoPath.2; BOIE9;ZHCN)");
//        httpost.setHeader("Content-Type","multipart/form-data; boundary=---------------------------7de2dd89070c");
//        httpost.setHeader("Connection", "Keep-Alive");
//        httpost.setHeader("Cache-Control", "no-cache");
//        httpost.setHeader("cookie", " user_name=wwaly%40qq.com; PHPSESSID=7gm1feaqg36u9dtr7k3u6slr82; _ga=GA1.2.1086720010.1374393983");
//        response = httpclient.execute(httpost);
//        entity = response.getEntity();
//        //输出页面内容以供查看
//        if (entity != null) {
//            String charset = EntityUtils.getContentCharSet(entity);
//            InputStream is = entity.getContent();
//            sb = new StringBuffer();
//            BufferedReader br = new BufferedReader(new InputStreamReader(is,
//                    "utf8"));
//            String line = null;
//            while ((line = br.readLine()) != null) {
//                sb.append(line);
//            }
//            is.close();
//            //打印，
//            System.out.println(sb);
//        }
//
//    }
//
//
//    public static void main(String[] args) throws ClientProtocolException, IOException {
//
//        start();
//
//
//    }
//
//
//    private static class DefaultHttpClient {
//    }
}
